<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFoodsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('foods'))
        Schema::create('foods', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->softDeletes();

            $table->string('category', 255)->default('')->comment('分类');
            $table->decimal('protein')->default(0.00)->comment('蛋白质');
            $table->decimal('fat')->default(0.00)->comment('脂肪');
            $table->decimal('carbohydrate')->default(0.00)->comment('碳水化合物');
            $table->decimal('sugar')->default(0.00)->comment('热量');
            $table->decimal('salt')->default(0.00)->comment('无机盐类');
            $table->decimal('calcium')->default(0.00)->comment('钙');
            $table->decimal('phosphorus')->default(0.00)->comment('磷');
            $table->decimal('iron')->default(0.00)->comment('铁');

            $table->index('category');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('foods');
    }
}
